package com.css.fxfzxczh.modules.lossReportManage.lossReportEscalation.repository.impl;

import com.css.fxfzxczh.modules.lossReportManage.lossReportEscalation.entity.MunicipalFacilities;
import com.css.fxfzxczh.modules.lossReportManage.lossReportEscalation.repository.LonOilPipLossRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class LonOilPipLossRepositoryImpl implements LonOilPipLossRepository {
    @Resource
    JdbcTemplate jdbcTemplate;

    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private static final String TABLE_NAME = "xczh_long_oil_pipeline_loss"; // 表名
    @Override
    public void deleteByXlrmId(String xlrmId) {
        String sql = "delete from  "+TABLE_NAME+"  where xlrm_id= '"+xlrmId+"'" ;
        jdbcTemplate.update(sql);
    }

    @Override
    public void batchSave(List<MunicipalFacilities> list) {
        SqlParameterSource[] beanSources = SqlParameterSourceUtils.createBatch(list.toArray());
        String sql = "INSERT INTO "+TABLE_NAME +
                " ( id,xlrm_id,fill_form_user,tel,fill_form_time,province,city,county,facility," +
                "grade_scale,original_value,place,damage_condition_desc,damage,destroy,ruined," +
                "urgent_repair,estimation_relied_on,estimation_loss,comment,total_loss,subitem,sequence,township,enterprise_name)" +
                "values (:id,:xlrmId,:fillFormUser,:tel,:fillFormTime,:province,:city,:county,:facility," +
                ":gradeScale,:originalValue,:place,:damageConditionDesc,:damage,:destroy,:ruined," +
                ":urgentRepair,:estimationReliedOn,:estimationLoss,:comment,:totalLoss,:subitem,:sequence,:township,:enterpriseName)";
        namedParameterJdbcTemplate.batchUpdate(sql, beanSources);
    }
}
